package com.atguigu.study.config;

import com.atguigu.study.listener.TestModelListener;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.util.List;

/**
 * @author Marco
 * @Description
 * @date 2025/8/18 20:02
 * @email 3293336923@qq.com
 */
@Component
public class LLMConfig {

    @Bean
    public ChatModel chatModel() {
        return
                OpenAiChatModel.builder()
                        .apiKey(System.getenv("ALIQW"))
                        .modelName("qwen-plus")
                        .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")

//                        设置日志
                        .logRequests(true)
                        .logResponses(true)
                        .listeners(List.of(new TestModelListener()))   //添加监听
                        .maxRetries(4) // 最大重试机制
                        .timeout(Duration.ofSeconds(2))  // 向大模型发送请求时，如果在指定的时间内么有收到响应，该请求将被中断并报  request  time  out
                        .build();
    }
}
